package com.neuedu.jxcboot.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.neuedu.jxcboot.web.interceptor.LoginInterceptor;

@Configuration
public class MvcConfig implements WebMvcConfigurer {
	// 注册拦截器
	@Bean
	public LoginInterceptor myInterceptor() {
		return new LoginInterceptor();
	}

	// 添加拦截器到spring mvc拦截器
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		/**
		 * <pre>
		 * 1.拦截所有请求，并排除指定的页面或路径 
		 * 2.排除规则需要与拦截规则一致，使用前置匹配的方法进行排除
		 * 3.排除后的请求不会进入拦击器进行拦截，在进行路径排除时需严谨考虑
		 * </pre>
		 */
		registry.addInterceptor(myInterceptor()).addPathPatterns("/**").excludePathPatterns("/images/**", "/libs/**")
				.excludePathPatterns("/login.html", "/index.html", "/user/login", "/validate");
	}

}